package com.ksp.wke.kspa03;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import static com.ksp.com.KSPCOM_BasConst.*;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ksp.api.KSPAPI_UserAgentUtil;
import com.ksp.api.KSPAPI_UsrAuth;
import com.ksp.dom.KSPDOM_ResDta;
import com.ksp.dom.KSPDOM_TabDta;
import com.ksp.dom.KSPDOM_User;

import net.minidev.json.JSONArray;
import static com.ksp.com.KSPCOM_BasConst.*;

/**
 * KSPA03 查询文章列表
 * @author anye
 *
 */
@Controller
public class KSPA03Controller {
	
	@Autowired
	private KSPA03Mapper kspa03Mapper;
	
	@RequestMapping("/art/KSPA03")
	@ResponseBody
	public KSPDOM_TabDta iniPam(ServletRequest request) {
		
		String wSorTyp = request.getParameter(SOR_TYP);
		String wDtaPge = request.getParameter(DTA_PGE);
		String wDtaLmt = request.getParameter(DTA_LMT);
		int wDtaPgeInt = Integer.parseInt(wDtaPge);
		int wDtaLmtInt = Integer.parseInt(wDtaLmt);
		
		Map<String, Object> wPamMap = new HashMap<>();
		wPamMap.put(SOR_TYP, wSorTyp);
		wPamMap.put(DTA_PGE, (wDtaPgeInt -1) * wDtaLmtInt);
		wPamMap.put(DTA_LMT, wDtaLmt);
		
		KSPDOM_TabDta wResDta = new KSPDOM_TabDta();
		try {
			wResDta = exeSrv(wPamMap);
		} catch (Exception e) {
			wResDta.setCode(1);
			wResDta.setMsg(e.getMessage());
			wResDta.setData(null);
			wResDta.setCount(0);
		}
		
		return wResDta;
	}

	public KSPDOM_TabDta exeSrv(Map<String, Object> pPamMap) {
		KSPDOM_TabDta wArtLstTbl = new KSPDOM_TabDta();
		
		List<Map<String, Object>> wArtTotalCntLst = kspa03Mapper.qryArtTotalCnt();
		if (wArtTotalCntLst != null && wArtTotalCntLst.size() > 0) {
			Map<String, Object> wArtTotalCntMap = wArtTotalCntLst.get(0);
			if (wArtTotalCntMap != null) {
				int wArtTotalCnt = Integer.parseInt(wArtTotalCntMap.get("ART_TOL").toString());
				wArtLstTbl.setCount(wArtTotalCnt);
			}
		}
		
		List<Map<String, Object>> wArtLstbyConLst = kspa03Mapper.qryArtLstbyCon(pPamMap);
		if (wArtLstbyConLst != null) {
			wArtLstTbl.setData(wArtLstbyConLst.toArray());
		}
		wArtLstTbl.setCode(0);
		wArtLstTbl.setMsg("");
		
		return wArtLstTbl;
	}
}
